package com.emergency.evaluate.dao;


import com.emergency.evaluate.domain.Report;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by Administrator on 2020/4/9.
 */
public interface ReportDao extends JpaRepository<Report, String>, JpaSpecificationExecutor<Report> {
    //根据ID查询报告
    @Query (value = "select r from Report r where r.id=:id")
    Report  findAllByReport( @Param ( "id" ) Long id);
    @Query (value = "select r from Report r where r.id=:id")
    List<Report>  findAllByReportId( @Param ( "id" ) Long id);


    //根据ID删除报告
    @Modifying
    @Query(value = "delete from Report r where r.id=:id")
    void deleteById(@Param ( "id" ) Long id);
    //根据人工评分表ID删除报告
    @Modifying
    @Query(value = "delete from Report  where manual.id=:manualId")
    void deleteByManual(@Param ("manualId") Long manualId);

    @Modifying
    @Query(value = "delete from Report  where plan.id=:planId")
    void deleteByPlanId(@Param ("planId") Long planId);

    //根据自动评分表ID删除报告
    @Modifying
    @Query(value = "delete from Report  where auto.id=:autoId")
    void deleteByAuto(@Param ("autoId") Long autoId);
}
